package edu.ruc.cluster.print;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.util.Scanner;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * 
 * put scanned character on JTextArea
 * @author
 * @date 
 * @version 1.0
 */
public class TextAreaLogAppender extends LogAppender {

    private JTextArea textArea;
    private JScrollPane scroll;

    /**
     * default constructor
     * @param textArea Printer name
     * @param scroll JTextArea
     * @throws IOException 
     */
    public TextAreaLogAppender(JTextArea textArea, JScrollPane scroll) throws IOException {
        super("textArea");
        this.textArea = textArea;
        this.scroll = scroll;
    }

    @Override
    public void run() {
        
        Scanner scanner = new Scanner(reader);
        while (scanner.hasNextLine()) {
            try {
                Thread.sleep(100);
                String line = scanner.nextLine();
                textArea.append(line);
                textArea.append("\n");
                line = null;
               
                scroll.getVerticalScrollBar().setValue(scroll.getVerticalScrollBar().getMaximum());
                            } catch (Exception ex) {
                
            }
        }
    }
}
